﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using 经典项目某某管理系统;
using 经典项目某某管理系统.Erp;

namespace MyShop
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Login_Click(object sender, EventArgs e)
        {
            if (this.UserName.Text.Equals("") || this.Passwd.Text.Equals(""))
            {
                MessageBox.Show("用户名或密码不可为空");
                return;
            }
            string sql = "select * from  SalesMan where Mobile = @Mobile and Pwd =@Pwd";
            DBHelper.PrepareSql(sql);
            DBHelper.SetParameter("Mobile", this.UserName.Text);
            DBHelper.SetParameter("Pwd", this.Passwd.Text);
            DataTable dt = DBHelper.ExecQuery();
            if (dt.Rows.Count > 0)
            {
                if (dt.Rows[0]["Role"].ToString().Equals("收银员"))
                {
                    FrmCash frmCash = new FrmCash();
                    frmCash.Show();
                    this.Hide();
                    //MessageBox.Show("不可登录");
                    return;
                }
                if (dt.Rows[0]["Role"].ToString().Equals("导购员"))
                {
                    //FrmMain frmMain = new FrmMain(dt.Rows[0]["SalesmanName"].ToString());
                    FrmMain frmMain = new FrmMain();
                    LoginCtl.SalesmamanID = Convert.ToInt32(dt.Rows[0]["SalesmanID"]);
                    LoginCtl.SalesmamanName = dt.Rows[0]["SalesmanName"].ToString();
                    LoginCtl.Role = dt.Rows[0]["Role"].ToString();
                    LoginCtl.Mobile = dt.Rows[0]["Mobile"].ToString();
                    frmMain.Show();
                    this.Close();
                }
                if (dt.Rows[0]["Role"].ToString().Equals("店长"))
                {
                    //FrmMain frmMain = new FrmMain(dt.Rows[0]["SalesmanName"].ToString());
                    FrmMain frmMain = new FrmMain();
                    LoginCtl.SalesmamanID = Convert.ToInt32(dt.Rows[0]["SalesmanID"]);
                    LoginCtl.SalesmamanName = dt.Rows[0]["SalesmanName"].ToString();
                    LoginCtl.Role = dt.Rows[0]["Role"].ToString();
                    LoginCtl.Mobile = dt.Rows[0]["Mobile"].ToString();
                    frmMain.Show();
                    this.Hide();
                }
            }
            else
            {
                MessageBox.Show("用户名或密码错误");
            }
        }
    }
}
